home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-17 | 5.9 KB | 204 lines | [TEXT/MPS ] |
-
- {-----------------------------------------------------------------------------------------}
- Add to UMacApp.p:
- PROCEDURE TView.PostRes;
- { Called on each view created by DoCreateViews(), in a post-order traversal,
- view creation is completed. }
- {-----------------------------------------------------------------------------------------}
-
- {-----------------------------------------------------------------------------------------}
- Change in UMacApp.TEvtHandler.p (thanks to John MacVeigh):
- {-----------------------------------------------------------------------------------------}
- FUNCTION TEvtHandler.DoCreateViews(itsDocument: TDocument;
- parentView: TView;
- itsRsrcID: INTEGER;
- subviewOffset: VPoint): TView;
-
- Var TopView: TView;
-
-
- {-------------------------------------------------------------------------------------}
-
- Procedure CallPostRes (aView: TView);
- {perform a (rather convoluted) post-order traversal of the
- subview lists, such that a view's subviews will all have
- PostRes called before the view itself is PosRes'd.}
-
- Var Unused: ArrayIndex;
-
- Function DummyTest (item: TView): Boolean;
- Begin
- CallPostRes (Item);
- DummyTest := False
- End;
-
- Begin
- If aView.fSubViews <> Nil Then
- If aView.fSubViews.IterateTil (DummyTest, kIterateBackward, Unused) <> Nil Then;
-
- aView.PostRes
- End; {CallPostRes}
-
- {-------------------------------------------------------------------------------------}
-
- { JLP: "ReallyDoCreateViews" is original (MacApp 2.0 Final) DoCreateViews() }
-
- {-------------------------------------------------------------------------------------}
- Function ReallyDoCreateViews(itsDocument: TDocument;
- parentView: TView;
- itsRsrcID: INTEGER;
- subviewOffset: VPoint): TView;
-
- VAR
- i: INTEGER;
- numViews: INTEGER;
- aView: TView;
- viewResource: ViewRsrcHndl;
- theViewInfo: ViewTemplatePtr;
- lastParentID: IDType;
- lastParent: TView;
- lastRoot: TView;
- firstView: TView;
- fi: FailInfo;
-
- PROCEDURE HdlDoCreateViews(error: OSErr;
- message: LONGINT);
-
- BEGIN
- IF viewResource <> NIL THEN { Don't constipate the heap }
- HUnLock(Handle(viewResource));
-
- FreeIfObject(firstView);
- firstView := NIL;
- END;
-
- {$IFC qDebug}
-
- PROCEDURE ReportTemplate;
-
- BEGIN
- WITH theViewInfo^ DO
- BEGIN
- WrLblSig('signature', itsSignature);
- WriteLn;
- WrLblSig('itsParentID', itsParentID);
- WrLblSig(', thisViewID', thisViewID);
- WriteLn;
- WrLblVPt('itsLocation', itsLocation);
- WrLblVPt(', itsSize', itsSize);
- Write('itsHSizeDet = ', ord(itsHSizeDet): 3);
- WriteLn(', itsVSizeDet = ', ord(itsVSizeDet): 3);
- WrLblBoolean(', isEnabled ', isEnabled);
- WriteLn;
- WriteLn('---------- end of view ----------');
- END;
- END;
- {$ENDC}
-
- BEGIN
- firstView := NIL; { Assume the worst. }
-
- viewResource := ViewRsrcHndl(GetResource('view', itsRsrcID));
- IF viewResource = NIL THEN
- BEGIN
- {$IFC qDebug}
- ProgramBreak(ConcatNumber('Unable to find ‘view’ resource #', itsRsrcID));
- {$ENDC}
- FailNilResource(viewResource);
- END;
-
- LockHandleHigh(Handle(viewResource));
-
- CatchFailures(fi, HdlDoCreateViews);
-
- numViews := viewResource^^.numViews;
- theViewInfo := @viewResource^^.theViews;
- lastParentID := kNoIdentifier;
- aView := parentView;
- lastRoot := parentView;
-
- FOR i := 1 TO numViews DO
- WITH theViewInfo^ DO
- BEGIN
- {$IFC qDebug}
- IF gIntenseDebugging THEN
- ReportTemplate;
- {$ENDC}
-
- IF LONGINT(itsParentID) = LONGINT(kNoIdentifier) THEN
- lastParent := parentView
- ELSE IF LONGINT(itsParentID) <> LONGINT(lastParentID) THEN
- BEGIN
- lastParent := aView; { Begin with last view created or parentView
- }
- WHILE (lastParent <> NIL) & (lastParent.fIdentifier <> itsParentID) DO
- lastParent := lastParent.fSuperView;
-
- IF (lastParent = NIL) & (lastRoot <> NIL) THEN
- IF aView <> NIL THEN
- lastParent := aView.FindSubView(itsParentID)
- ELSE
- lastParent := lastRoot.FindSubView(itsParentID);
-
- {$IFC qDebug}
- IF lastParent = NIL THEN
- ProgramBreak('Unable to find parent view for template');
- {$ENDC}
- END;
- lastParentID := itsParentID;
-
- IF LONGINT(itsSignature) = LONGINT('incl') THEN
- BEGIN
- aView := ReallyDoCreateViews(itsDocument, lastParent, includeRsrcID, gZeroVPt);
- OffsetPtr(theViewInfo, SIZEOF(ViewTemplate) - SIZEOF(Str255) + SIZEOF(INTEGER));
- END
- ELSE IF LONGINT(itsSignature) = LONGINT('inc@') THEN
- BEGIN
- aView := ReallyDoCreateViews(itsDocument, lastParent, includeRsrcID,
- itsSubViewOffset);
- OffsetPtr(theViewInfo, SIZEOF(ViewTemplate) - SIZEOF(Str255) +
- SIZEOF(INTEGER) + SIZEOF(VPoint));
- END
- ELSE
- aView := CreateAView(itsDocument, lastParent, Ptr(theViewInfo));
-
- IF aView = NIL THEN
- LEAVE;
- IF ((subviewOffset.h <> 0) | (subviewOffset.v <> 0)) & (aView.fSuperView =
- parentView) & (parentView <> NIL) THEN
- aView.Locate(aView.fLocation.h + subviewOffset.h, aView.fLocation.v +
- subviewOffset.v, kDontInvalidate);
-
- IF i = 1 THEN
- BEGIN
- firstView := aView;
- IF Member(aView, TWindow) & (parentView = NIL) THEN
- parentView := aView;
- END;
-
- IF (lastRoot = NIL) & (aView <> NIL) & (aView.fSuperView = NIL) THEN
- lastRoot := aView;
- END;
-
- HUnLock(Handle(viewResource));
- Success(fi);
-
- ReallyDoCreateViews := firstView {*** what DoCreateViews used to return}
- End; {ReallyDoCreateViews}
-
- Begin {DoCreateViews}
- If fNextHandler <> Nil
- Then DoCreateViews := fNextHandler.DoCreateViews
- (itsDocument, parentView, itsRsrcID, subviewOffset)
- Else Begin
- TopView := ReallyDoCreateViews (itsDocument, parentView, itsRsrcID, subviewOffset);
-
- If TopView <> Nil Then Begin
- CallPostRes (TopView);
-
- TopView.AdjustSize; { Make sure size gets adjusted by the size determiners }
- End;
-
- DoCreateViews := TopView
- End
- End; {DoCreateViews}